﻿using HelperLibrary;
using Quartz;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace AVCJobDispatcherLinux.TaskJobEngine
{
    /// <summary>
    /// 作业任务
    /// </summary>
    public class TaskJob : IJob
    {
        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task Execute(IJobExecutionContext context)
        {
            string id = context.JobDetail.JobDataMap["id"].ToString();
            JobInfo jobInfo = TaskJobManager.JobList.First(j => j.Id == id);
            return Task.Run(() =>
            {
                try
                {
                    string data = HTTPHelper.HttpGet(jobInfo.ExecuteUrl, null);
                }
                catch (Exception ex)
                {
                    LogHelper.LogErr(new Exception($"地址【{jobInfo.ExecuteUrl}】执行错误：{ex.Message}"));
                }
            });
        }
    }
}
